<template>
  <div class="layoutCon">
    <div class="breadcrumb">
      <router-link class="home" to="/"></router-link> > <router-link to="/my">마이페이지</router-link> > 알림
    </div>
    <div class="layoutMy">
      <user-center-nav></user-center-nav>
      <div class="myCon">
        <div class="comList">
          <div class="tit">
            <h2>알림 내역</h2>
          </div>
          <div class="loadList" v-loading="pageConfig.loading&&pageConfig.page==1">
            <ul v-if="noticeList.length">
              <li v-for="(item,index) in noticeList" :key="index">
                <div class="time"><em>{{item.type_name}}</em>{{item.created_at}}</div>
                <a href="javascript:;" target="_self" class="txt" @click="readNotice(item.id,item.tid,item.type)">
                  <strong>{{item.title}}</strong>
                </a>
                <el-button class="r btn" @click="readNotice(item.id,item.tid,item.type)">자세히 보기</el-button>
              </li>
            </ul>
            <div class="notData" v-if="!pageConfig.loading&&noticeList.length==0">내용 없음</div>
            <div class="loadMore" v-if="!pageConfig.isAll">
              <el-button type="primary" :loading="pageConfig.loading" @click="loadMore" class="btnMore">더보기</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
import { notifications, readNotice } from '@/api';
import userCenterNav from '@/components/userCenterNav';

export default {
  name:'',
  components:{userCenterNav},
  props:[],
  data(){
    return {
      pageConfig:{
        page:1,
        per:20,
        loading:false,
        isAll:true
      },
      noticeList:[],
    }
  },
  computed:{},
  created(){
    this.getNoticeList()
  },
  mounted(){},
  methods:{
    async getNoticeList(){
      this.pageConfig.loading=true;
      let res = await notifications({page:this.pageConfig.page,per:this.pageConfig.per});
          if (res.code == 200) {
            this.pageConfig.page+=1;
            let _arry=res.data.data;
              if(_arry.length){
                _arry.forEach((o)=>{
                  o.isOpen=false;
                })
                this.noticeList=this.noticeList.concat(_arry);
              }
            !res.data.next_page_url?(this.pageConfig.isAll=true):(this.pageConfig.isAll=false);
            this.pageConfig.loading=false;            
          }else{
            this.pageConfig.loading=false;  
          }
    },
    async readNotice(id,tid,type){
      let res = await readNotice({id:id});
          if (res.code == 200) {}
      let _path='';
      if(type=='QA'){
        _path='/service/QNAview'
      }else if(type=='order'||type=='server_over'||type=='server_start'){
        _path='/my/coachInfo'
      }
      if(_path){
        this.$router.push({ path: _path, query: {  id:tid } });
      }
    },
    loadMore(){
      !this.pageConfig.loading&&this.getNoticeList();
    }
  },
  watch:{}
}
</script>
<style lang="scss" scoped>
 @import "@/assets/styles/my.scss";
</style>